#ifndef _YDEFINE_H
#define _YDEFINE_H
#include <stdlib.h>

/*======= Build for type of device */
/* default */
#ifndef _BIT_DEVICE
#define _32_BIT     32
#define _BIT_DEVICE _32_BIT
#endif
/* for future */
#ifndef _BIT_DEVICE
#define _64_BIT     64
#define _BIT_DEVICE _64_BIT
#endif
#ifndef _BIT_DEVICE
#define _128_BIT    128
#define _BIT_DEVICE _128_BIT
#endif

/*======= Global type definition */
#ifndef _YDEFINE_BOOLEAN
#define _YDEFINE_BOOLEAN
/** Boolean type for c! */
typedef enum boolean {false, true} boolean;
#endif
#ifndef _YDEFINE_IS_REPLY
#define _YDEFINE_IS_REPLY
/** Boolean type for c! */
typedef enum g_reply {g_replyNo, g_replyYes, g_replyFail, 
    g_replyLesser, g_replyEqual, g_replyGreater} g_reply;
#endif

/*======= Global function */
/*--- if error encounter will exit(EXIT_FAILURE) */
#define FN_OOPS(msg)        perror(msg); exit(EXIT_FAILURE);
#define FN_MALLOC_CAST_ERRMSG_EXIT(assign,cast,param,msg) \
    if ((assign = (cast) malloc(param)) == NULL) {FN_OOPS(msg)}
#define FN_MALLOC_CAST_EXIT(assign,cast,param) \
    FN_MALLOC_CAST_ERRMSG(assign, cast, param, "Error: malloc() ")
#define FN_MALLOC_ERRMSG_EXIT(assign,param,msg) \
    if ((assign = malloc(param)) == NULL) {FN_OOPS(msg)}
#define FN_MALLOC_EXIT(assign,param) \
    FN_MALLOC_ERRMSG(assign, param, "Error: malloc() ")
/*--- if error encounter will NOT exit program */
#define FN_MALLOC_CAST_ERRMSG(assign,cast,param,msg) \
    if ((assign = (cast) malloc(param)) == NULL) {perror(msg);}
#define FN_MALLOC_CAST(assign,cast,param) \
    FN_MALLOC_CAST_ERRMSG(assign, cast, param, "Error: malloc() ")
#define FN_MALLOC_ERRMSG(assign,param,msg) \
    if ((assign = malloc(param)) == NULL) {perror(msg);}
#define FN_MALLOC(assign,param) \
    FN_MALLOC_ERRMSG(assign, param, "Error: malloc() ")

#endif /* _YDEFINE_H */
